import request from './request'
import { AxiosPromise } from 'axios'

// 获取工单物料列表
export function spareWork(data) {
  return request({
    url: '/work/spare/getList',
    method: 'post',
    data,
  })
}

/**
 * 审核工单物料
 * @param data - 请求参数
 */
export function checkOrderSpare(data: OrderAPIRequest.AuditSparePart): AxiosPromise<APIResponse> {
  return request({
    url: '/work/spare/checkOrderSpare',
    method: 'put',
    data,
  })
}

/**
 * 根据工单物料ID获取工单物料详情
 * @param id - 物料id
 */
export function OrderSpareDetailProjectInfo(
  id: string,
): AxiosPromise<OrderAPIResponse.MaterialDetail> {
  return request({
    url: '/work/spare/getDetail/' + id,
    method: 'get',
  })
}

/**
 * 根据工单ID获取工单详情的工单物料列表
 * @param data - 请求参数
 * @param workId - 工单id
 */
export function getOrderDetailWorkSpareList(
  data: { limit: number; page: number },
  workId: string,
): AxiosPromise<OrderAPIResponse.MaterialList> {
  return request({
    url: `/work/spare/getOrderDetailWorkSpareList/${workId}`,
    method: 'post',
    data,
  })
}

/**
 * 根据工单ID获取工单公司地址
 * @param workId - 工单id
 */
export function getWorkUserAddress(workId: string): AxiosPromise<OrderAPIResponse.CustomerAddress> {
  return request({
    url: '/work/user/getWorkUserAddress/' + workId,
    method: 'get',
  })
}

/**
 * 根据工单ID获取网点地址
 * @param workId - 工单id
 */
export function getOrderNetworkAddress(
  workId: string,
): AxiosPromise<OrderAPIResponse.NetworkAddress> {
  return request({
    url: '/work/order/getOrderNetworkAddress',
    method: 'get',
    params: { workId },
  })
}

/**
 * 保存或修改工单物料
 * @param data - 请求参数
 */
export function spareSaveOrder(data: OrderAPIRequest.SparePartSave): AxiosPromise<APIResponse> {
  return request({
    url: '/work/spare/save',
    method: 'post',
    data,
  })
}

/**
 * 根据工单物料ID获取工单物料详情的物料信息
 * @param id - 物料id
 */
export function getOrderSpareMaterial(
  materialId: string,
): AxiosPromise<OrderAPIResponse.MaterialDetailSparePartList> {
  return request({
    url: '/work/spare/getOrderSpareMaterial/' + materialId,
    method: 'get',
  })
}

/**
 * 获取审核前的工单物料信息
 * @param id - 物料id
 */
export function getBeforeCheckOrderSpareDetail(
  id: string,
): AxiosPromise<OrderAPIResponse.SparePartInfoBeforeAudit> {
  return request({
    url: '/work/spare/getBeforeCheckOrderSpareDetail/' + id,
    method: 'get',
  })
}

/**
 * 获取工单物料日志列表
 * @param data - 请求参数
 * @param id - 物料id
 */
export function OrderSpareLogList(
  data: { limit: number; page: number },
  id: string,
): AxiosPromise<OrderAPIResponse.MaterialOperateLog> {
  return request({
    url: '/work/spare/getOrderSpareLogList/' + id,
    method: 'post',
    data,
  })
}

// 获取工单物料旧件列表
export function getBackList(data) {
  return request({
    url: '/work/spare/return/getList',
    method: 'post',
    data,
  })
}

// 编辑配件
export function spareUpdate(data) {
  return request({
    url: '/work/spare/update',
    method: 'post',
    data,
  })
}
